﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HeroDream
{
    class GameWorld
    {
        /// <summary>
        /// 英雄
        /// </summary>
        private Hero hero;

        /// <summary>
        /// 任务大厅
        /// </summary>
        private TaskRoom taskRoom;

        /// <summary>
        /// 商店
        /// </summary>
        private Shop shop;

        /// <summary>
        /// 铁匠铺
        /// </summary>
        private Smithy smithy;

        public GameWorld()
        {
            Console.WriteLine("大陆生成中");
        }

        public void StartGame()
        {
            Console.WriteLine("请输入你的姓名：");
            string name = Console.ReadLine();
            hero = new Hero(name);
            hero.OutPut();
            taskRoom = new TaskRoom();

            shop = new Shop();
            shop.Output();

            smithy = new Smithy();

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("------------------------------------------------");
                Console.WriteLine("请选择你的操作");
                Console.WriteLine("1:查看个人信息");
                Console.WriteLine("2:接取任务");
                Console.WriteLine("3:购买装备");
                Console.WriteLine("4:锻造委托");
                Console.WriteLine("5:请求锻造师傅开工");
                Console.WriteLine("6:合成装备");
                Console.WriteLine("0:退出游戏");
                Console.WriteLine("------------------------------------------------");
                string str = Console.ReadLine();
                int operate = Convert.ToInt32(str);
                switch (operate)
                {
                    case 1:
                        hero.OutPut();
                        break;
                    case 2:
                        TaskRun();
                        break;
                    case 3:
                        BuyEquip();
                        break;
                    case 4:
                        Forging();
                        break;
                    case 5:
                        DoSmithy();
                        break;
                    case 6:
                        Combine();
                        break;
                    case 0:
                        Console.WriteLine("退出中");
                        return;

                    default:
                        break;

                }
            }
        }

        public void TaskRun()
        {
            taskRoom.CreateTask();
            taskRoom.OutPut();
            Console.WriteLine("---------请选择你需要接取的任务---------");
            string str = Console.ReadLine();
            int index = Convert.ToInt32(str);

            Task task = taskRoom.GetTask(index);
            if (task == null)
            {
                Console.WriteLine("任务接取失败");
                return;
            }
            else
            {
                task.OutPut();
                //做任务
                hero.DoTask(task);
            }
        }


        public void BuyEquip()
        {
            shop.Output();
            Console.WriteLine("---------请选择你需要购买第几件装备---------");
            string str = Console.ReadLine();
            int index = Convert.ToInt32(str);
          int price=  shop.GetPrice(index);

            if (hero.Coin >= price)
            {
                Equipment equipment=  shop.Buy(index);
                hero.EquipItem(equipment);
                hero.Coin = hero.Coin - price;

            }
            else
            {
                Console.WriteLine($"金币不足,当前你金币为{  hero.Coin},需要的金币为{price}");
            }
        }

        public void Forging()
        {
            Console.WriteLine("---------请选择你需要锻造第几件装备---------");
            string str = Console.ReadLine();
            int index = Convert.ToInt32(str);
            Equipment equipment = hero.GetEquip(index);
            smithy.SetForging(equipment.BeForging);
        }


        public void DoSmithy()
        {
            smithy.StartForging();
        }

        public void Combine()
        {
            hero.CombineEquip();

        }

        public static void Test()
        {
             GameWorld gameWorld = new GameWorld();
             gameWorld.StartGame();
            Equipment weapon = new Weapon("武器",1);
            weapon.Output();
            Equipment armor = new Armor("护甲",2);
            armor.Output();
        }
    }
}
